local skel = fk.CreateSkill {
  name = "lb__jiezhi",
}

local DIY = require "packages.diy_utility.diy_utility"

Fk:loadTranslationTable {
  ["lb__jiezhi"] = "解桎",
  [":lb__jiezhi"] = "出牌阶段结束时，你可以弃置一张手牌，然后获得本回合进入弃牌堆中与此牌类型颜色均不同的牌。若获得牌数大于1，你可重复此流程并令你本回合手牌上限+1（至多三次）。",

  ["#lb__jiezhi"] = "解桎：你可以弃置一张手牌，然后获得本回合进入弃牌堆中所有与此牌类型颜色均不同的牌",
  ["@lb__jiezhi_num-turn"] = "解桎",

  ["$lb__jiezhi1"] = "这就结束了？这就满足了？",
  ["$lb__jiezhi2"] = "科学没有界限，我更没有。",
}

skel:addEffect(fk.EventPhaseEnd, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Play and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      prompt = "#lb__jiezhi",
      skill_name = "lb__jiezhi",
      include_equip = false,
      skip = true,
    })
    event:setCostData(self, { cards = cards })
    return #cards > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:getCardById(event:getCostData(self).cards[1])
    room:throwCard(card, skel.name, player, player)
    local ids = table.filter(DIY.getCenterCards(room), function(id)
      local c = Fk:getCardById(id)
      return c.type ~= card.type and c.color ~= card.color
    end)
    if #ids > 0 then
      room:obtainCard(player, ids, true, fk.ReasonJustMove, player, skel.name)
    end
    if #ids > 1 and player:usedSkillTimes(skel.name, Player.HistoryPhase) <= 3 then
      room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn)
      room:addPlayerMark(player, "@lb__jiezhi_num-turn")
      self:doCost(event, nil, player)
    end
  end,
})

skel:addAcquireEffect(function(self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

return skel
